package jp.sinya;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * jsp交互
 */
public class DemoServlet13 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setStatus(200);
        resp.setHeader("Content-Type", "text/html; charset=utf-8");

        //获取参数
        int query1 = Integer.valueOf(req.getParameter("num1"));
        int query2 = Integer.valueOf(req.getParameter("num2"));
        int sum = query1 + query2;

        req.setAttribute("sum", sum);
        //这个jsp的路径是相对于web目录的
        req.getRequestDispatcher("/test3.jsp").forward(req, resp);
    }
}